require "proto/scene/message/ReqDarkAlleyFormationsMessage"
require "proto/scene/message/ReqDarkEntryMessage"
require "proto/scene/message/ReqDarkInfoMessage"
require "proto/scene/message/ReqDarkApplyMessage"
DarkStreetHandler = {}
local reqDarkInfoCallback = nil
local this = DarkStreetHandler
---返回暗巷阵容
function DarkStreetHandler.ResDarkAlleyFormationsHandler(msg)
    if msg.state ~= 0 then return end
    local formations = {}
    for k,v in pairs(msg.formations) do
        formations[k] = tostring(v)
    end
    logicMgr.FormationManager.SetFormation(EnumConst.FormationType.DarkStreet,formations)

    FireEvent(Config.EventType.DarkStreetFormationUpdate)
end
---返回暗巷信息
function DarkStreetHandler.ResDarkAlleyInfoHandler(msg)
    if msg.state ~= 0 then return end
    logicMgr.DarkStreetMgr.isOpen = msg.status == 1
    logicMgr.DarkStreetMgr.joinNum = msg.joinNum
    logicMgr.DarkStreetMgr.resCountInWeek = msg.gotMoney
    logicMgr.DarkStreetMgr.resCompensationInWeek = msg.gotMoney2
    logicMgr.DarkStreetMgr.startOrEndTime = tonumber(tostring(msg.nextTime/1000))
    if reqDarkInfoCallback then
        reqDarkInfoCallback()
        reqDarkInfoCallback = nil
    end
end
---返回暗巷房间状态
function DarkStreetHandler.ResDarkRoomStateHandler(msg)
    if msg.state ~= 0 then return end
    FireEvent(Config.EventType.DarkStreetRoomStatusChange,msg.status)
    RedRob.ClientBattle.isRoomDestroy = msg.status == 0
    if msg.status== 0 then
        logicMgr.DarkStreetMgr.Track_exitSuccess(1, 2)
        logicMgr.DarkStreetMgr.Track_activityStart()
    elseif msg.status == 1 then
        logicMgr.DarkStreetMgr.Track_activityStart()
    end
end
---返回暗巷结算
function DarkStreetHandler.ResDarkResultHandler(msg)
    if msg.state ~= 0 then return end
    logicMgr.DarkStreetMgr.SetResult(msg.killNum,msg.money,msg.killStreak)
    FireEvent(Config.EventType.DarkStreetResult)
    logicMgr.DarkStreetMgr.Track_battle(msg)
end
---请求暗巷的阵容信息
function DarkStreetHandler.ReqDarkAlleyFormations()
    local msg = ReqDarkAlleyFormationsMessage.New()
    sendReqMessage(msg)
end
---请求进入暗巷
function DarkStreetHandler.ReqDarkEntry(form)
    local msg = ReqDarkEntryMessage.New()
    msg.formations = form
    sendReqMessage(msg)
end
---请求暗巷信息
function DarkStreetHandler.ReqDarkInfo(callback)
    reqDarkInfoCallback = callback
    local msg = ReqDarkInfoMessage.New()
    sendReqMessage(msg)
end
---请求暗巷报名操作
function DarkStreetHandler.ReqDarkApply(isEnter,formations)
    local msg = ReqDarkApplyMessage.New()
    msg.type = isEnter and 0 or 1
    msg.formations = formations or {}
end
function DarkStreetHandler.ResDarkMatchSucc(msg)
    logicMgr.DarkStreetMgr.isMatchSuc = true
    FireEvent(Config.EventType.ResDarkMatchSuc)
end
